<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    
 *
 * 
 */
namespace osc\mobile\controller;
use osc\common\controller\Base;
use \think\Db;
use think\Session;
use think\Request;
class Account extends Base
{
	protected function _initialize(){
		parent::_initialize();						
		define('UID',is_login());	
		//手机版
		if(!UID){		
			$this->redirect('login/login');							
		}
		if (!Session::has("username")) {

            $this->redirect('login/login');

        }			
	}
	
	function check_login(){
		
		$uid=is_login();
		
		if(!$uid){			
			$this->redirect('login/login');					
		}

		$username = session('username');
		
		if(!$username)
		{
			$this->redirect('login/login');					
		}
		return $uid;
	}
	
	function index(){
		$username = session('username');
		$start = input('param.start');
		$end = input('param.end');

		if($start && $end){
			$map = [
					'username' => $username,
					'create_time' => array(['>',strtotime($start)],['<',strtotime($end)])
			];
			$list = Db::name('bonus')->where($map)->order('create_time desc')->paginate(10,false, [
					'query' => Request::instance()->param(),//不丢失已存在的url参数
			]);
		}else{

			$list = Db::name('bonus')
					->where(array('username'=>$username,'type'=>0))
					->order('create_time desc')
					->paginate(10);
		}
		$page=$list->render(); //获取分页
		$user_info = Db::name('member')->where(array('username'=>$username))->find();
		$this->assign('start',$start);
		$this->assign('end',$end);
		$this->assign('user_info',$user_info);
		$this->assign('page',$page);
		$this->assign('list',$list);
		$this->assign('empty',"<span style='margin-left:20px;'>没有数据</span>");
				
		$this->assign('top_title','我的奖励');
		$this->assign('SEO',['title'=>'我的奖励-'.config('SITE_TITLE')]);
		$this->assign('empty','<tr><td colspan="20">暂无记录~</td></tr>');		
		return $this->fetch();
	}

	



	


}